home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / ABox 1.9.5 / CPlus Files / ABUControls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  8.2 KB  |  376 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABUControls.c
  15.  
  16. NAME
  17.     ABUControls.c, part of the ABox project source code,
  18.     responsible for mix-in handling the AboutBox Controls stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                ttempel@monmouth.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <ttempel@monmouth.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     14 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  38.                             release and the associated Universal Headers from Apple:
  39.                             most methods that returned references now have "Ref" at
  40.                             the end of their methods names to prevent possible collisions
  41.                             with datatypes and classes of the same name (older versions
  42.                             of the compiler didn't have a problem with this).
  43.     25-oct-95    -    ty    -    changes for "const" usage under CW7; simplification of Boolean
  44.                             query methods
  45.  
  46. */
  47.  
  48. /*===========================================================================*/
  49.  
  50. /*======= Segmentation directives ========*/
  51.  
  52. #ifdef USE_MANUAL_SEGMENTATION
  53. #pragma segment ty
  54. #endif
  55.  
  56. /*============ Header files ==============*/
  57.     
  58. #include     "ABUControls.h"
  59.  
  60. /*=============== Globals ================*/
  61.  
  62. /*================ CODE ==================*/
  63.  
  64.  
  65. /*=============================== ABUControls::ABUControls ================================*/
  66. ABUControls::ABUControls(void)
  67. {
  68.     cList = NULL;
  69.     cNumber = 0;
  70. }    // end ABUControls
  71.  
  72.  
  73. /*=============================== ABUControls::~ABUControls ================================*/
  74. ABUControls::~ABUControls(void)
  75. {
  76.     if (cList)
  77.     {
  78.         DisposPtr((Ptr)cList);
  79.         cList = NULL;
  80.     }
  81.     cNumber = 0;
  82.     
  83. }    // end ~ABUControls
  84.  
  85.  
  86.  
  87.  
  88.  
  89. /*=============================== ABUControls::FlashControl ===============================*/
  90. //
  91. //    FlashControl will simulate a user-click on the
  92. //    control specified. Specifically, it simulates the visual 
  93. //    aspects of a user clicking or selecting a control...useful when
  94. //    intercepting events in an event filter proc.
  95. //
  96. //    based upon DialogBits by CK Haun, Apple Dev Tech Suppt.
  97. //
  98. //
  99. //    is called by:
  100. //        DoEvent
  101. //
  102. Boolean    ABUControls::FlashControl (ControlHandle ctrl)
  103. {
  104.     Boolean        active = false;
  105.     long        timer;
  106.     const long    duration = 8;
  107.     
  108.     if (ctrl) 
  109.     {
  110.         active = IsControlActive(ctrl);
  111.         if (active)
  112.         {
  113.             HiliteControl(ctrl, true);
  114.             Delay(duration, &timer);                //    wait about 8 ticks so they can see it
  115.             HiliteControl(ctrl, false);
  116.         }
  117.     }    //    end if block
  118.         
  119.     return active;
  120. }    //    end of function FlashControl()
  121.  
  122.  
  123.  
  124.  
  125. /*=============================== ABUControls::IsControlActive ===============================*/
  126. //
  127. //    IsControlActive will return a value of either true or
  128. //    false, indicative of whether the given control is indeed
  129. //    active or not.
  130. //
  131. //
  132. //    is called by:
  133. Boolean    ABUControls::IsControlActive (ControlHandle ctrl)
  134. {
  135.     if (ctrl)
  136.         if ((*ctrl)->contrlHilite == kABdeactivateControl)
  137.             return false;
  138.         else
  139.             return true;
  140.     else
  141.         return false;
  142. } // end IsControlActive()
  143.  
  144.  
  145.  
  146.  
  147.  
  148. /*=============================== ABUControls::CheckControl ===============================*/
  149. //
  150. //    CheckControl will set/unset a control.
  151. //
  152. //
  153. //    is called by:
  154. OSErr    ABUControls::CheckControl (ControlHandle ctrl, Boolean setCondition)
  155. {
  156.     if (ctrl)
  157.     {
  158.         HiliteControl (ctrl, (setCondition ? kABactivateControl : kABdeactivateControl));
  159.         return noErr;
  160.     } else {
  161.         return paramErr;
  162.     } // end if else block
  163.  
  164. } // end CheckControl()
  165.  
  166.  
  167.  
  168.  
  169.  
  170. /*=============================== ABUControls::CheckAllControls ===============================*/
  171. //
  172. //    CheckAllControls will set/unset all the controls in a window.
  173. //
  174. //
  175. //    is called by:
  176. OSErr    ABUControls::CheckAllControls (WindowPtr theWindow, Boolean setCondition)
  177. {
  178.     ControlHandle    ctrlHandle = NULL;
  179.     OSErr            error = noErr;
  180.     
  181.     //    begin here...
  182.     
  183.     if (theWindow)
  184.     {
  185.         //    nothing, so check to see if we can walk the
  186.         //    window's control list and find the nth control
  187.         ctrlHandle = ((WindowPeek)theWindow)->controlList;
  188.     
  189.         while (ctrlHandle)
  190.         {
  191.             error = CheckControl (ctrlHandle, setCondition);
  192.             ctrlHandle = (*ctrlHandle)->nextControl;
  193.         } // end while loop
  194.     } else {
  195.         error = paramErr;
  196.     } // end if else block
  197.  
  198.     return error;
  199. } // end CheckAllControls()
  200.  
  201.  
  202.  
  203.  
  204.  
  205. /*=============================== ABUControls::GetControlHandle ===============================*/
  206. //
  207. //    GetControlHandle will return a handle to a given control item
  208. //    in the given dialog box. If the item is _not_ a control then
  209. //    a kABbadControlHandle is returned.
  210. //
  211. //    based upon SnatchHandle() by CK Haun, Apple Dev Tech Suppt.
  212. //
  213. //    Handy for setting checkboxes and radio buttons
  214. //
  215. //
  216. //    is called by:
  217. //
  218. ControlHandle    ABUControls::GetControlHandle (GrafPtr window, short theGetItem)
  219. {
  220.     short            index = 1;
  221.     short             itemType;
  222.     Rect             itemRect;
  223.     Handle            itemHandle = NULL;
  224.     ControlHandle    ctrlHandle = NULL;
  225.     
  226.     if (!(window && (theGetItem > 0))) 
  227.     {
  228.         return NULL;
  229.     } // end if block
  230.     
  231.     GetDialogItem(window, theGetItem, &itemType, &itemHandle, &itemRect);
  232.     
  233.     if (itemHandle)
  234.     {
  235.         //    GetDialogItem returned something...
  236.         
  237.         ctrlHandle = (ControlHandle)itemHandle;
  238.         if (!(itemType & ctrlItem))
  239.         {
  240.             ctrlHandle = NULL;
  241.         } // end if else block
  242.     } else {
  243.         //    nothing, so check to see if we can walk the
  244.         //    window's control list and find the nth control
  245.         ctrlHandle = ((WindowPeek)window)->controlList;
  246.     
  247.         while (ctrlHandle && (index != theGetItem))
  248.         {
  249.             ctrlHandle = (*ctrlHandle)->nextControl;
  250.             ++index;
  251.         } // end while loop
  252.         
  253.         if (index != theGetItem)
  254.             ctrlHandle = NULL;
  255.     
  256.     } // end if block
  257.     
  258.     return ctrlHandle;
  259.     
  260. }    //    end of function GetControlHandle
  261.  
  262.  
  263.  
  264.  
  265. /*=============================== ABUControls::CountControls ===============================*/
  266. //
  267. //    CountControls will count the number of control items in the given window.
  268. //
  269. short    ABUControls::CountControls (WindowPtr window)
  270. {
  271.     short            number = 0;
  272.     ControlHandle    ctrl = NULL;
  273.     
  274.     //    begin here...
  275.     
  276.     if (!window)
  277.         return number;
  278.         
  279.     ctrl = ((WindowPeek)window)->controlList;
  280.     while (ctrl)
  281.     {
  282.         ++number;
  283.         ctrl = (*ctrl)->nextControl;
  284.     } // end while loop
  285.     
  286.     return number;
  287. } // end CountControls
  288.  
  289.  
  290.  
  291.  
  292.  
  293. /*=============================== ABUControls::SaveControlStates ===============================*/
  294. //
  295. //    SaveControlStates will save the states of all controls in the given
  296. //    window, for restoration later.
  297. //
  298. OSErr    ABUControls::SaveControlStates (WindowPtr window)
  299. {
  300.     OSErr            error = noErr;
  301.     ControlHandle    ctrl = NULL;
  302.     short            index;
  303.     
  304.     //    begin here...
  305.     
  306.     if (!window)
  307.         return paramErr;
  308.  
  309.     if (cList)
  310.     {
  311.         DisposPtr((Ptr)cList);
  312.         cList = NULL;
  313.         cNumber = 0;
  314.     } // end if block
  315.     
  316.     cNumber = CountControls(window);
  317.     
  318.     if (!cNumber)
  319.     {
  320.         return paramErr;
  321.     } else {
  322.         cList = (ABControlListPtr)NewPtrClear (cNumber * sizeof(ABControlList));
  323.         error = MemError();
  324.     } // end if else block
  325.     
  326.     if (error)
  327.         return error;
  328.         
  329.     ctrl = ((WindowPeek)window)->controlList;
  330.     index = 0;
  331.     while (ctrl)
  332.     {
  333.         cList[index].handle = ctrl;
  334.         cList[index].state = (*ctrl)->contrlHilite;
  335.         ++index;
  336.         ctrl = (*ctrl)->nextControl;
  337.     } // end while loop
  338.     
  339.     return error;
  340. } // end SaveControlStates
  341.  
  342.  
  343.  
  344.  
  345.  
  346. /*=============================== ABUControls::RestoreControlStates ===============================*/
  347. //
  348. //    RestoreControlStates will save the states of all controls in the given
  349. //    window, for restoration later.
  350. //
  351. OSErr    ABUControls::RestoreControlStates (WindowPtr window)
  352. {
  353.     OSErr            error = noErr;
  354.     short            index;
  355.     
  356.     //    begin here...
  357.     
  358.     if (!(window && cList && cNumber))
  359.         return paramErr;
  360.  
  361.     for (index = 0; index < cNumber; ++index)
  362.     {
  363.         HiliteControl(cList[index].handle, cList[index].state);
  364.     } // end for loop
  365.     
  366.     return error;
  367. } // end RestoreControlStates
  368.  
  369.  
  370.  
  371.  
  372. //    end of file.
  373.  
  374.  
  375.  
  376.